<!--
 * @Author: 地址列表
 * @Date: 2020-06-29 15:10:03
 * @LastEditTime: 2020-07-06 14:29:35
 * @LastEditors: 範遠茂
 * @Description: In User Settings Edit
 * @FilePath: \JK商城\jkshopping\src\pages\payment\order\components\mes\address\components\addressList.vue
--> 
<template>
  <div class="addressList">
    <ul class="ul_item">
      <li class="li_item" v-for="(item,idx) of addressList" :key="item.id">
        <div class="title">
          <span class="name">{{item.consignee}}</span>
          <span class="phone">{{item.consignee_mobile}}</span>
          <div class="address">
            <p
              class="text"
            >{{item.country_name}}{{item.province_name}}{{item.city_name}}{{item.area_name}}{{item.consignee_address}}</p>
          </div>
          <van-radio-group v-model="radio">
            <van-radio class="check" :name="item.id" @click="address(idx)"></van-radio>
          </van-radio-group>
        </div>
      </li>
    </ul>
    <div class="btn">
      <router-link to="/addAddress">
      <div class="btn_add" >
        <p>+添加新收件地址</p>
      </div>
      </router-link>
    </div>
  </div>
</template>

<script>
import * as api from "@/api/apiList/user/address/address.js";
export default {
  data() {
    return {
      radio: "",
      checked: true,
      addressList: []
    };
  },
  methods: {
    //地址列表请求方法
    async API_getAddress() {
      return await api.get_address();
    },
    //点击发送选中的地址信息
    address(idx) {
      console.log(this.addressList[idx]);
      let address = {
        id: this.addressList[idx].id,
        name: this.addressList[idx].consignee,
        phone: this.addressList[idx].consignee_mobile,
        country_name: this.addressList[idx].country_name,
        province_name: this.addressList[idx].province_name,
        city_name: this.addressList[idx].city_name,
        area_name: this.addressList[idx].area_name,
        consignee_address: this.addressList[idx].consignee_address
      };
      this.$eventBus.$emit("address", address);
      setTimeout(()=>{
      this.$router.push("./order")
      },500)
    }
  },

  async created() {
    //调用接口方法
    let address = await this.API_getAddress();
    if (address.data.code === 200) {
      console.log(address.data.data.data);
      this.addressList = address.data.data.data;
    }
  }
};
</script>

<style lang="scss" scoped>
.addressList {
  .ul_item {
    margin-top: 10px;
    .li_item {
      position: relative;
      background-color: #fff;
      border-bottom: 1px solid #ccc;
      //   width: 100%;
      //   height: 80px;
      padding: 20px;
      box-sizing: border-box;
      display: flex;
      //   justify-content: center;
      .title {
        float: left;
        .name {
          margin-right: 10px;
          width: 100%;
        }
        .phone {
        }
        .address {
          width: 260px;
          margin-top: 10px;
          // border: 1px solid black;
          .text {
            color: rgb(173, 166, 166);
          }
        }
      }
      .check {
        position: absolute;
        right: 10px;
        bottom: 40%;
      }
    }
  }
  .btn {
    .btn_add {
      width: 95%;
      height: 40px;
      background-color: #fa0334b9;
      margin-top: 10px;
      margin-left: 50%;
      transform: translate(-50%);
      // z-index: 999;
      p {
        color: #fff;
        text-align: center;
        line-height: 40px;
        font-size: 18px;
      }
    }
  }
}
</style>